package cn.itcast.hotel.controller;

import cn.itcast.hotel.pojo.PageResult;
import cn.itcast.hotel.pojo.RequestParams;
import cn.itcast.hotel.service.IHotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    cn.itcast.hotel.service.IHotelService iHotelService;

    /**
     * 查询所有
     * @param params
     * @return
     * @throws IOException
     */
    @PostMapping("/list")
    public PageResult search(@RequestBody RequestParams params) throws IOException {
        return iHotelService.search(params);
    }

    /**
     * 过滤查询，检索
     * @param params
     * @return
     * @throws IOException
     */
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params) throws IOException {
        return iHotelService.filters(params);
    }

    @GetMapping("/suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix) throws IOException {

        return iHotelService.getSuggestions(prefix);
    }


}
